const USER_KEY = "user";

export const useStore = () => {
  return {
    user: JSON.parse(localStorage.getItem(USER_KEY)) || {
      userName: null,
      token: null,
      accountName: null,
    },
    updateUser: (userName, token, accountName) => {
      localStorage.setItem(
        USER_KEY,
        JSON.stringify({
          userName: userName,
          token: token,
          accountName: accountName
        })
      );
    },
    clearUser: () => {
      localStorage.removeItem(USER_KEY);
    },
  };
};
